package com.example.kt_base.s2

//TODO 32.Kotlin语言的函数引用学习
fun main() {
    //函数引用
    //lambda属于函数类型的对象，需要把普通函数methodResponseResult变成函数类型的对象（函数引用）
    login("Derry2", "123456", ::methodResponseResult)
}

private fun methodResponseResult(msg: String, code: Int) {
    println("最终登录结果是：msg:$msg,code:$code")
}

//模拟数据库 SQLServer
const val USER_NAME_SAVE_DB4 = "Derry"
const val USER_PSW_SAVE_DB4 = "123456"

inline fun login(name: String, psw: String, lambda: (String, Int) -> Unit) {
    if (USER_NAME_SAVE_DB4 == name && USER_PSW_SAVE_DB4 == psw) {
        lambda("登录成功", 200)
    } else {
        lambda("登录失败", 400)
    }
}